package net.aiotos.common.dto;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.*;

@Data
@NoArgsConstructor
public final class DataDTO {

    /**
     * name : 开关3
     * readwrite : 0
     * timestamp : 1611748936077
     * defaultvalue : False
     * maxvalue : 999
     * value : 1
     * minvalue : 0
     * data_date : 2021-04-25 15:55:50
     * valuetype : BOOL
     * refreshcycle : 0
     * device_oid : 52076119
     * tpl_id : 5
     * data_oid : a0b3
     * regexp :
     * sensibility : 0
     * config : {"equation":null,"param":{},"disabled":false,"proxy":{"index":"","pointer":null},"parentId":"33dd","position":[],"class":null}
     * id : 3
     * unit :
     * description :
     */
    /**
     * 数据点名称（在绑定设备实例下唯一）
     */
    @JSONField(name = "name")
    private String name;
    @JSONField(name = "readwrite")
    private Integer readwrite;
    @JSONField(name = "timestamp")
    private Long timestamp;
    @JSONField(name = "defaultvalue")
    private String defaultvalue;
    @JSONField(name = "maxvalue")
    private Double maxvalue;
    @JSONField(name = "value")
    private String value;
    @JSONField(name = "minvalue")
    private Double minvalue;
    @JSONField(name = "data_date")
    private String dataDate;
    /**
     * 数据点类型
     */
    @JSONField(name = "valuetype")
    private String valuetype;
    @JSONField(name = "refreshcycle")
    private int refreshcycle;
    /**
     * 设备实例ID
     */
    @JSONField(name = "device_oid")
    private String deviceOid;
    @JSONField(name = "tpl_id")
    private Integer tplId;
    /**
     * 数据点ID（在绑定设备实例下唯一）
     */
    @JSONField(name = "data_oid")
    private String dataOid;
    @JSONField(name = "regexp")
    private String regexp;
    @JSONField(name = "sensibility")
    private String sensibility;
    /**
     * 字段允许用户根据需要自定义字段
     */
    @JSONField(name = "config")
    private JSONObject config;
    /**
     * 数据生成的ID(对外不开放本字段)
     */
    @Getter(value= AccessLevel.PRIVATE)
    @JSONField(name = "id")
    private Integer id;
    /**
     * 数据点数据值单位
     */
    @JSONField(name = "unit")
    private String unit;
    @JSONField(name = "description")
    private String description;

    /**
     * config字段结构类
     * @param tClass
     * @param <T>
     * @return
     */
    public final <T> T getConfig(Class<T> tClass) {
        return config.toJavaObject(tClass);
    }
}
